package scale.sim;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class ScaleSimApp {

	/**
	 * Main method for Scale simulator
	 * @param args [Port]
	 */
	public static void main(String[] args) {

		JFrame frame = new JFrame("Scale Simulator - Group 15");
		
		int custom = JOptionPane.showConfirmDialog(frame,
				"Start Scale on port 8000", "Listen on port",
				JOptionPane.YES_NO_CANCEL_OPTION);
		// YES = 0 NO = 1 CANCEL = 2

		switch (custom) {
		case 0:
			 new Thread(new ScaleServer()).start();
			break;
		case 1:
			boolean run = true;
			while (run) {
				String newport = JOptionPane.showInputDialog(
						"Type in the new port no.", null);
				if (newport != null) {
					try {
						int port = Integer.parseInt(newport);
						 new Thread(new ScaleServer(port)).start();
						run = false;
					} catch (Exception e) {
						e.printStackTrace();
					}
				} else {
					run = false;
					custom = 2;
				}
			}
			break;
		default:
			frame.dispose();
			System.exit(0);
			break;
		}
		
	}

}
